﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MglMES
{
    [Serializable]
    public class MglMESBase<T>
    {
        public string ProtocolNO { get; set; }
        public int MsgNO { get; set; }
        public int NeedReply { get; set; }
        public string CmdID { get; set; }
        public string EID { get; set; }
        public List<T> Data { get; set; }
    }

    public class CHeartbeat
    {
        private int _heartBeat;
        public CHeartbeat(int m_heartBeat)
        {
            _heartBeat = m_heartBeat;
        }
        public int Heartbeat
        {
            get
            {
                return _heartBeat;
            }
            set
            {
                _heartBeat = value;
            }
        }
    }

    public class CReturnCode
    {
        private int _returnCode;
        public CReturnCode(int m_returnCode)
        {
            _returnCode = m_returnCode;
        }
        public int ReturnCode
        {
            get
            {
                return _returnCode;
            }
            set
            {
                _returnCode = value;
            }
        }
    }

    public class CEquipment
    {
        /// <summary>
        /// 设备编码
        /// </summary>
        public string EquipID { get; set; }
        /// <summary>
        /// 状态时间
        /// </summary>
        public string DateTime { get; set; }
    }

    public class CEquipmentStatus : CEquipment
    {
        /// <summary>
        /// 运行-1；待机-2；故障-3；维修-4；停机-5
        /// </summary>
        public string Status { get; set; }
      
    }

    public class CEquipmentAlarm : CEquipment
    {
        /// <summary>
        /// 日期
        /// </summary>
        public string Date { get; set; }
        /// <summary>
        /// 班次
        /// </summary>
        public string ShiftType { get; set; }
        /// <summary>
        /// 报警内容
        /// </summary>
        public string AlertInfo { get; set; }
        /// <summary>
        /// 报警次数
        /// </summary>
        public string AlertCnt { get; set; }
    }

    public class CEquipmentStatistic : CEquipment
    {
        /// <summary>
        /// 人员工号
        /// </summary>
        public string UserID { get; set; }
        /// <summary>
        /// 电解液物料批次
        /// </summary>
        public string ElcLotID { get; set; }
        /// <summary>
        /// 电芯编码
        /// </summary>
        public string CellID { get; set; }
        /// <summary>
        /// 电芯状态（OK/NG）
        /// </summary>
        public string Result { get; set; }
        /// <summary>
        /// NG 原因
        /// </summary>
        public string NGReason { get; set; }
        /// <summary>
        /// 前称重
        /// </summary>
        public string WeighBeforeInject { get; set; }
        /// <summary>
        /// 后称重
        /// </summary>
        public string WeighAfterInject { get; set; }
        /// <summary>
        /// 初始注液量
        /// </summary>
        public string InjectWeight1st { get; set; }
        /// <summary>
        /// 出料注液量
        /// </summary>
        public string InjectWeight2nd { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public string BeginTime { get; set; }
        /// <summary>
        /// 完成时间
        /// </summary>
        public string EndTime { get; set; }
        /// <summary>
        /// 真空静置时间
        /// </summary>
        public string VacStandTime { get; set; }
        /// <summary>
        /// 真空静置负压压力
        /// </summary>
        public string VacStandPress { get; set; }
        /// <summary>
        /// 封口后称重
        /// </summary>
        public string WeighAfterSeal { get; set; }
        /// <summary>
        /// 封口实际温度
        /// </summary>

        public string SealTemp { get; set; }
        /// <summary>
        /// 封口实际时间
        /// </summary>
        public string SealTime { get; set; }
        /// <summary>
        /// 封口实际压力
        /// </summary>
        public string SealPress { get; set; }
        /// <summary>
        /// 注液真空度
        /// </summary>
        public string InjectVac { get; set; }
        /// <summary>
        /// 电解液损失量
        /// </summary>
        public string LosePercent { get; set; }
        /// <summary>
        /// 1-装配注液；2-化成注液；
        /// </summary>
        public string Process { get; set; }


    }


    /// <summary>
    /// 心跳消息，向服务端标识设备在线
    /// </summary>
    [Serializable]
    public class M001A : MglMESBase<CHeartbeat> { }
    /// <summary>
    /// Host 收到设备端发送的心跳消息后的回复
    /// </summary>
    [Serializable]
    public class M001B : MglMESBase<CReturnCode> { }




    /// <summary>
    /// 设备状态信息上报
    /// </summary>
    /// 
    [Serializable]
    public class M101A : MglMESBase<CEquipmentStatus> { }
    /// <summary>
    /// 设备状态信息上报回复
    /// </summary>
    /// 
    [Serializable]
    public class M101B : MglMESBase<CReturnCode> { }




    /// <summary>
    /// 设备报警信息 Top20 上报
    /// </summary>
    /// 
    [Serializable]
    public class M402A : MglMESBase<CEquipmentAlarm> { }
    /// <summary>
    /// 设备报警信息 Top20 上报回复
    /// </summary>
    /// 
    [Serializable]
    public class M402B : MglMESBase<CReturnCode> { }




    /// <summary>
    /// 设备生产结果数据上报
    /// </summary>
    /// 
    [Serializable]
    public class M709A : MglMESBase<CEquipmentStatistic> { }
    /// <summary>
    /// 设备生产结果数据上报回复
    /// </summary>a
    /// 
    [Serializable]
    public class M709B : MglMESBase<CReturnCode> { }

    public static class MglJsonExtention
    {
        public static T FromJSON<T>(this string json)
        {
            return  JsonConvert.DeserializeObject<T>(json);
        }
        public static string ToJSON(this object obj)
        {
            return  JsonConvert.SerializeObject(obj);
        }
    }
}
